'''
Created on May 8, 2012
TC ID: Ecom_5047
Desc: Kiem thu chuc nang tao mot bai kiem tra
@author: lavang
'''
import unittest
import time
from HTMLTestRunner import HTMLTestRunner
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.lessonInformationFunc import clickOnLesson
from Functions.testsFunc import clickOnTests, clickOnAddTest, addTest,\
    clickOnLinkTest, isTestAddedSuccessfully

username=readData("username",index=2)
password=readData("password",index=2)
tm_lesson=readData("lessonName",index=3)
tm_test=readData("testName",index=2)
tm_description="This is 15' minutes Test"
tm_parentUnit=readData("subUnitName",index=2)
class Ecom_5047(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5047(self):
        print "Buoc 1: Dang nhap website"
        login(self,username,password)
        
        print "Buoc 2: Click vao mot bai hoc"
        clickOnLesson(self,tm_lesson)
        
        print "Buoc 3: Click vao 'Tests'"
        clickOnTests(self)
        
        print "Buoc 4: Click vao 'Add test' "
        clickOnAddTest(self)
        
        print "Buoc 5: Tao bai kiem tra"
        addTest(self,tm_test,tm_description,tm_parentUnit)
        
        print "Buoc 6: Tro ve trang 'Test' "
        clickOnLinkTest(self)
        
        print "Buoc 7: Xac nhan tao bai kiem tra thanh cong"
        self.assertTrue(isTestAddedSuccessfully(self,tm_test,tm_parentUnit), "Failed!")
        print "Passed! Bai kiem tra duoc tao thanh cong"
        
    def tearDown(self):
        endCondition(self)



if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5047)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang tao bai kiem tra'
                    )
    runner.run(suite)